//package com.lqzs.businessmanager.service
//
//import android.annotation.SuppressLint
//import android.os.Build
//import android.os.Handler
//import android.os.Looper
//import android.util.Log
//import android.view.accessibility.AccessibilityNodeInfo
//import androidx.annotation.RequiresApi
//import com.lqzs.businessmanager.Config
//import com.lqzs.businessmanager.Config.Companion.SCROLL_TIMER
//import com.lqzs.businessmanager.base.BaseViewModel
//import com.lqzs.businessmanager.service.AccessibilitySampleService.Companion
//import com.lqzs.businessmanager.utils.PreferencesUtil
//import com.lqzs.businessmanager.utils.nodeOnClick
//import com.lqzs.businessmanager.utils.scrollByNode
//import com.lqzs.businessmanager.utils.setEditText
//import kotlinx.coroutines.delay
//import java.util.concurrent.atomic.AtomicInteger
//
//class MeiTuanUserViewModel : BaseViewModel() {
//
//    val TAG: String = javaClass.name
//    @SuppressLint("StaticFieldLeak")
//    private lateinit var mService: AccessibilitySampleService
//    val type = AtomicInteger(0)
//    val handler = Handler(Looper.getMainLooper())
//
//    @RequiresApi(Build.VERSION_CODES.O)
//    fun init(service: AccessibilitySampleService){
//        mService = service
//        type.set(0)
//    }
//
//    suspend fun handlerMeiTuan(rowNode: AccessibilityNodeInfo){
//        Log.e(TAG,"${type.get()}")
//        when(type.get()){
//            0->{
//                //查询搜索按钮
//                val serchBt = rowNode.findAccessibilityNodeInfosByViewId(Config.serch_bt)
//                serchBt?.let {
//                    if (it.size>0) {
//                        nodeOnClick(it[0])
//                        type.set(1)
//                    }
//                }
//            }
//            1->{
//                val titleBt =  rowNode.findAccessibilityNodeInfosByViewId(Config.userTitle)
//                titleBt?.let {
//                    if (it.size>0) {
//                        nodeOnClick(it[0])
//                        type.set(2)
//                    }
//                }
//            }
//            2->{
//                val bt_clear = rowNode.findAccessibilityNodeInfosByViewId(Config.userClearEditText)
//                val editText = rowNode.findAccessibilityNodeInfosByViewId(Config.userEditText)
//                bt_clear?.let {
//                    if (it.size>0) {
//                        nodeOnClick(it[0])
//                        delay(1000)
//                        editText?.let { editTexts->
//                            if (editTexts.size>0) {
//                                if (setEditText(editTexts[0],"张亮麻辣烫")){
//                                    type.set(3)
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//            3->{
//                val btSearch = rowNode.findAccessibilityNodeInfosByViewId("com.sankuai.meituan:id/search")
//                btSearch?.let {
//                    if (it.size>0) {
//                        nodeOnClick(it[0])
//                        type.set(4)
//                    }
//                }
//            }
//            4->{
//
//                val byList = rowNode.findAccessibilityNodeInfosByViewId("com.sankuai.meituan:id/pagecontainer_recyclerview")
//                byList?.let {
//                    if (it.size>0) {
//                        initTimer(it[0],Config.MT_Timer)
//                    }
//                }
////                for(i in 0 until rowNode.childCount){
////                    val  childNodeInfo = rowNode.getChild(i) ?: continue
////                    val className = childNodeInfo.className ?: continue
////
////                    childNodeInfo.text?.toString()?.trim()?.let {
////                        if (it == "最新"){
////                            childNodeInfo.parent?.let {parentNode ->
////                                nodeOnClick(parentNode)
////                            }
////                        }
////                    }
////                    handlerMeiTuan(childNodeInfo)
////                }
//            }
//        }
//
//    }
//
//    private var mRunnable : Runnable?=null
//    private fun initTimer(scrollNodeInfo : AccessibilityNodeInfo,timer:Long){
//        if (mRunnable == null){
//            mRunnable = Runnable {
//                Log.d(Companion.TAG,"执行定时任务：${scrollNodeInfo.contentDescription}")
//                scrollByNode(mService,scrollNodeInfo,50,400)
//                initTimer(scrollNodeInfo,timer)
//            }
//            mRunnable?.let {
//                handler.postDelayed(it,1000*20)
//            }
//        }
//    }
//
//    private fun handlerLog(rowNode: AccessibilityNodeInfo): Boolean {
//        if (rowNode.childCount >0){
//            for (i in 0 until rowNode.childCount){
//                val  childNodeInfo = rowNode.getChild(i) ?: continue
//                val className = childNodeInfo.className ?: continue
//                Log.e(AccessibilitySampleService.TAG," $className       ${childNodeInfo.viewIdResourceName}        ${childNodeInfo.text?.toString()?.trim()}")
//                handlerLog(childNodeInfo)
//            }
//        }
//        return false
//    }
//
//}